@extends('admin.layout.admin_main')

@section('content')
    <section class="content ">
        <include file="Public/common/message"/>
        <div class="row">
            @include('admin.auth.common.sys_menu',['name' => 'user'])
            <div class="col-md-10">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">员工列表</h3>
                        <div class="box-tools pull-right">
                            @if (Auth::guard('admin')->user()->canPerm('admin-user-create'))
                            <a href="/admin/user/create" class="btn btn-primary pull-right btn-sm"><i class="fa fa-plus"></i> 添加管理员</a>
                            @endif
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box">
                        <div class="box-body table-responsive">
                            <table id="admin_list" class="table table-bordered table-hover">
                                <thead>
                                <tr role="row">
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>所属角色</th>
                                    <th class="screen767_td_display_none">联系电话</th>
                                    <th class="screen767_td_display_none">加入时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($users as $vo)
                                    <tr>
                                        <td>{{$vo->id}}</td>
                                        <td>{{$vo->name}}</td>
                                        <td>
                                            @foreach($vo->roles as $role)
                                                <span class="label label-success">{{$role->display_name}}</span>
                                            @endforeach
                                        </td>
                                        <td class="screen767_td_display_none">{{$vo->phone}}</td>
                                        <td class="screen767_td_display_none">{{$vo->created_at}}</td>
                                        <td class="">
                                            @if($vo->status==1)
                                                <span class="label label-success">正常</span>
                                            @else
                                                <span class="label label-danger">无效</span>
                                            @endif</td>
                                        <td>
                                            @if($vo->id !== 1)
                                                @if (Auth::guard('admin')->user()->canPerm('admin-user-edit'))
                                                    <a class="btn btn-primary btn-sm" href="/admin/user/{{$vo->id}}/edit"><i class="fa fa-pencil"></i></a>
                                                @endif
                                                @if (Auth::guard('admin')->user()->canPerm('admin-user-delete'))
                                                    <a class="btn btn-danger btn-sm" href="javascript:void(0)" data-url="/admin/user/{{$vo->id}}/delete" onclick="nform.delete(this)"><i class="fa fa-trash-o"></i></a>
                                                @endif
                                                @if (Auth::guard('admin')->user()->canPerm('admin-user-attach'))
                                                    <a class="btn btn-success btn-sm" href="javascript:void(0)" data-title="选择权限" data-url="/admin/role/select" data-id="{{$vo->id}}" onclick="show_modal(this,'user_id')">角色</a>
                                                @endif
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <script>
        function show_modal(obj, name){
            var id = $(obj).attr('data-id');
            var url = $(obj).attr('data-url')+"?"+name+"="+id;
            var title = $(obj).attr('data-title');
            layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: 0.3,
                area: ['70%', '80%'],
                content: url,
            });
        }

        function call_back(flag)
        {
            if(flag == 1){
                goUrl('/admin/users');
            }
        }
    </script>
@endsection
